home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 September
/
PCWorld_2006-09_cd.bin
/
v cisle
/
hexer
/
mpth_17.exe
/
{app}
/
scripts
/
Structure Viewer
/
zip.mps
< prev
Wrap
Text File
|
2006-03-19
|
8KB
|
249 lines
option title, "Zip archive (.zip) structure"
=
=
= Tiny Hexer script for .zip archives view in
= mirkes.de's tiny hex editor
=
= (C) markus stephany, tinyhexer[at]mirkes[dot]de
=
INCLUDE 'def.mps'
option GlobalVars, 1
option ReadTags, 1
option target, structureviewer
= open active editor and goto current position/0
var editor file
editor = fileopen('::current')
if ((param_count > 0) and (dword(params(0))==1))
fileseek editor, 0
else
fileseek editor, filegetprop(editor, 'selstart')
endif
var start dword
start = filegetprop(editor, 'position')
= open browser window
var browser file
browser = fileopen('::browser', 'c')
filesetprop browser, 'accepttags', 1
filewrite browser "<font color=",'"',"blue",'"',"><b><u>Zip archive file structure:</u></b></font>\n\n"
filesetprop browser, 'accepttags', 0
filewrite browser "File: '",filegetprop(editor, 'filename'),"'\nPosition: ",start,"\n\n"
var _word word _dword dword _text text _pos dword _word1 word _dword1 dword _word2 word _word3 word
repeat
= read the zip structure signature
_pos = filepos(editor)
fileread editor _dword
if _dword == 0x04034b50
filewrite browser "Local file header at ",_pos,":\n\n"
call HEADERSIG
fileread editor _word
filewrite browser " Word\tVersionNeed\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tFlag\t\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tComprMethod\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tModifTime\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tModifDate\t",_word,"\n"
fileread editor _dword
filewrite browser " DWORD\tCRC32\t\t",_dword,"\n"
fileread editor _dword1
filewrite browser " DWORD\tComprSize\t",_dword1,"\t(": filewrite browser DEC(_dword1): filewrite browser " bytes)\n"
fileread editor _dword
filewrite browser " DWORD\tUncomprSize\t",_dword,"\t(":filewrite browser DEC(_dword):filewrite browser " bytes)\n"
fileread editor _word
filewrite browser " Word\tFileNameLen\t",_word,"\n"
fileread editor _word1
filewrite browser " Word\tExtraLen\t",_word1,"\n\n"
if _word > 0
tagvar _word, filepos(editor), _word
call TEXTOUT, 'filename', _word
filewrite browser "\n"
endif
if _word1 > 0
tagvar _word1, filepos(editor), _word1
call TEXTOUT, 'extra data', _word1
filewrite browser "\n"
endif
if _dword1 > 0
tagvar _dword1, filepos(editor), _dword1
call NOTEXTOUT, 'compressed data', _dword1
filewrite browser "\n"
endif
filewrite browser "\n\n"
else
if _dword == 0x02014b50
filewrite browser "Central file header at ",_pos,":\n\n"
call HEADERSIG
fileread editor _word
filewrite browser " Word\tVersionBy\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tVersionNeed\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tFlag\t\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tComprMethod\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tModifTime\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tModifDate\t",_word,"\n"
fileread editor _dword
filewrite browser " DWORD\tCRC32\t\t",_dword,"\n"
fileread editor _dword1
filewrite browser " DWORD\tComprSize\t",_dword1,"\t(":filewrite browser DEC(_dword1):filewrite browser " bytes)\n"
fileread editor _dword
filewrite browser " DWORD\tUncomprSize\t",_dword,"\t(":filewrite browser DEC(_dword):filewrite browser " bytes)\n"
fileread editor _word
filewrite browser " Word\tFileNameLen\t",_word,"\n"
fileread editor _word1
filewrite browser " Word\tExtraLen\t",_word1,"\n"
fileread editor _word2
filewrite browser " Word\tFileComLen\t",_word2,"\n"
fileread editor _word3
filewrite browser " Word\tDiskStart\t",_word3,"\n"
fileread editor _word3
filewrite browser " Word\tIntFileAttr\t",_word3,"\n"
fileread editor _dword
filewrite browser " DWORD\tExtFileAttr\t",_dword,"\n"
fileread editor _dword
_text = "RelOfLoc"
tagvar _text, _dword, 0
filewrite browser " DWORD\t",_text,"\t",_dword,"\n\n"
if _word > 0
tagvar _word, filepos(editor), _word
call TEXTOUT, 'filename', _word
filewrite browser "\n"
endif
if _word1 > 0
tagvar _word1, filepos(editor), _word1
call TEXTOUT, 'extra data', _word1
filewrite browser "\n"
endif
if _word2 > 0
tagvar _word2, filepos(editor), _word2
call TEXTOUT, 'file comment', _word2
filewrite browser "\n"
endif
filewrite browser "\n\n"
else
if _dword == 0x06054b50
filewrite browser "End Of Central file header at ",_pos,":\n\n"
call HEADERSIG
fileread editor _word
filewrite browser " Word\tThisDiskNo\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tCDiskNo\t\t",_word,"\n"
fileread editor _word
filewrite browser " Word\tCEntries\t",_word,"\t\t(":filewrite browser DEC(_word):filewrite browser " entries)\n"
fileread editor _word
filewrite browser " Word\tEntries\t\t",_word,"\t\t(":filewrite browser DEC(_word):filewrite browser " entries)\n"
fileread editor _dword
filewrite browser " DWORD\tCSize\t\t",_dword,"\n"
fileread editor _dword
_text = "COfs"
tagvar _text, _dword, 0
filewrite browser " DWORD\t",_text,"\t\t",_dword,"\n"
fileread editor _word
filewrite browser " Word\tCommentLen\t",_word,"\n\n"
if _word > 0
filewrite browser "\n "
tagvar _word, filepos(editor), _word
call TEXTOUT, 'zip comment', _word
filewrite browser "\n "
endif
goto end
else
error 'Unknown zip structure signature: ', Text(_dword)
endif
endif
endif
until 0
@@end
fileclose editor
fileclose browser
end
@@STRIPTEXT
= convert unprintable chars and trim to max 127 chars
var ws text o text du none i byte c char b3 byte
b3 = 0
copytags du ws
if textlen(ws) > 127
b3 = 1
ws = textcopy(ws,1,127)
endif
i = 1
o = ''
while i <= textlen(ws)
c = char(textcopy(ws,i,1))
if (c < ' ') or (c == "'")
o = o+'.'
else
o = o+c
endif
inc i 1
endwhile
ws = "\0x27"+o+"\0x27"
if b3: ws = ws+'...':endif
copytags ws du
return
@@DECOUT
number_radix = 10
number_prefix = ''
var _r1 varref
pop _r1
filewrite browser deref(_r1)
number_radix = 16
number_prefix = '0x'
return
@@TEXTOUT:= output a string, convert white spaces, max 127 chars
var t text d dword
pop d
pop t
call DECOUT @d
filewrite browser " byte(s) of ",t,"\t"
fileread editor ws d
call STRIPTEXT
filewrite browser ws
return
@@NOTEXTOUT:= output amount of data
pop d
pop t
call DECOUT @d
filewrite browser " byte(s) of ",t,"\t"
fileseek editor d, FILE_CURRENT
return
@@HEADERSIG
var t1 text b1 byte b2 byte
fileseek editor _pos
fileread editor t1 2
fileread editor b1
fileread editor b2
filewrite browser " DWORD\tHeaderSig\t\0x27",t1,"\0x27 ",b1," ",b2,"\t(",_dword,")\n"
return